/// <reference path="../../../Navigation/ItemsNavigator.debug.js" />

Type.registerNamespace("BM");

BM.Dependant = function(determinant, path, actionInfos) {
    this.determinant = determinant;    
    this.path = path;
    this.actionInfos = actionInfos
}

BM.Dependant.prototype = {
    getActions: function() {
        if (this.actions == null) {
            this.actions = new Array();
            for (var i = 0; i < this.actionInfos.length; i++) {
                this.actions.push(this.createAction(this.actionInfos[i]));
            }
        }
        return this.actions;
    },


    createAction: function(actionInfo) {
        var type = eval(actionInfo.JsType);
        return new type(this, actionInfo);
    },

    run: function() {
        for (var i = 0; i < this.getActions().length; i++) {
            this.getActions()[i].run();
        }
    },

    getId: function() {
        if (this.id == null) {
            this.id = BM.ItemsNavigator.getSelectedId(this.determinant.getItem(), this.path);
        }
        return this.id;
    },

    getItem: function() {
        if (this.item == null) {
            this.item = MItem.getById(this.getId());
        }
        return this.item;
    },

    clearItem: function() {
        this.item = null;
    },

    getBasis: function() {
        if (this.basis == null) {
            this.basis = MBasis.getById(this.getId());
        }
        return this.basis;
    }
}

BM.Dependant.registerClass("BM.Dependant");
